package com.sl.au.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sl.au.entity.ChanceTrance;
import com.sl.au.entity.EXDEGiveInvoiceHistoryWithContract;
import com.sl.au.repository.EXDEPayBillingHistoryRepository;
import com.sl.au.service.EXDEPayBillingHistoryService;

/**
 * 合同开票历史视图层
 * @author yry
 * 2017-02-20
 */
@Service("EXDEPayBillingHistoryService")
@Transactional
public class EXDEPayBillingHistoryServiceImpl extends BaseServiceImpl implements EXDEPayBillingHistoryService {

	@Autowired
	EXDEPayBillingHistoryRepository exdePayBillingHistoryRepository;
	
	/**
	 * 获取开票历史信息
	 */
	@Override
	public List<EXDEGiveInvoiceHistoryWithContract> getMyPage(int start, int length, Map<String, String> condition) {
		Page<EXDEGiveInvoiceHistoryWithContract> pages=null;
		Pageable pageable=new PageRequest(start/length,length,Sort.Direction.DESC,"dPaymentDate");
		//System.out.println(condition.get("key"));
		//判断查询条件是否存在
		if(condition.get("key") != null && !condition.get("key").toString().equals("")){
			pages = exdePayBillingHistoryRepository.findAllTrance(condition.get("superior"),condition.get("key"),pageable);
		}else{
			pages = exdePayBillingHistoryRepository.findAllTrance(condition.get("superior"),pageable);
		}
		//System.out.println(pages);
		return pages.getContent();
	}

	@Override
	public EXDEPayBillingHistoryRepository getRepository() {
		return this.exdePayBillingHistoryRepository;
	}

	/**
	 * 获取开票历史信息条数
	 */
	@Override
	public long getMyPageCount(int start, int length, Map<String, String> condition) {
		long count = 0;
		if(condition.get("key") != null && !condition.get("key").equals("")){
			count = exdePayBillingHistoryRepository.findAllTrancegetCount(condition.get("superior"),condition.get("key"));
		}else{
			count = exdePayBillingHistoryRepository.findAllTrancegetCount(condition.get("superior"));
		}
		return count;
	}


}
